package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.PictureAddReq;
import com.yimils.core.goods.dto.PictureUpdateReq;
import com.yimils.core.goods.serivce.PictureService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class PictureController {
    @Resource(name = "pictureService")
    PictureService pictureService;

    @PostMapping("/picture/save")
    public RspBase savePicture(@RequestBody PictureAddReq pictureAddReq) {
        if (pictureService.savePicture(pictureAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/picture/update")
    public RspBase updatePicture(@RequestBody PictureUpdateReq pictureUpdateReq) {
        if (pictureService.updatePicture(pictureUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/picture/delete")
    public RspBase deletePicture(List<Long> pictureIds) {
        if (pictureService.deletePicture(pictureIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/picture/list")
    public RspBase listPicture() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", pictureService.listPicture());
        return rsp;
    }
}
